<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>获取当前子元素是其父元素下子元素的排位</title>
</head>
<body>
<ul id="wrap">
	<li>1</li>
	<li>1</li>
	<li>1</li>
	<li id="li">3</li>
	<li>1</li>
	<li>1</li>
	<li>1</li>
	<li>1</li>
</ul>
<script>
var wrap = document.querySelector('#wrap')
var li = document.querySelector('#li')
const getIndex = el => {
    if (!el) {
        return -1
    }
    let index = 0
    do {
        index++
    } while (el = el.previousElementSibling);
    return index
}
console.log(getIndex(li))
</script>	
</body>
</html>